home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2001 May / SGI IRIX Base Documentation 2001 May.iso / usr / share / catman / p_man / cat5 / realtime.z / realtime
Encoding:
Text File  |  2001-04-17  |  22.5 KB  |  463 lines

  1.  
  2.  
  3.  
  4. rrrreeeeaaaallllttttiiiimmmmeeee((((5555))))                                                        rrrreeeeaaaallllttttiiiimmmmeeee((((5555))))
  5.  
  6.  
  7.  
  8. NNNNAAAAMMMMEEEE
  9.      _rrrr_eeee_aaaa_llll_tttt_iiii_mmmm_eeee, _ssss_cccc_hhhh_eeee_dddd_uuuu_llll_eeee_rrrr - introduction to realtime and scheduler facilities
  10.  
  11. DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  12.      The IRIX operating system provides a rich set of realtime programming
  13.      features that are collectively referred to as the REACT extensions.
  14.  
  15.      This document introduces the components of REACT, including:  bounded
  16.      response time, clocks, timers, signals, virtual memory control,
  17.      asynchronous I/O, POSIX threads, scheduling policies, realtime priority
  18.      band, processor isolation, process binding, and interrupt redirection.
  19.  
  20.      _BBBB_oooo_uuuu_nnnn_dddd_eeee_dddd _RRRR_eeee_ssss_pppp_oooo_nnnn_ssss_eeee _TTTT_iiii_mmmm_eeee
  21.  
  22.      A realtime system provides bounded and usually fast response to specific
  23.      external events, allowing applications to schedule a particular thread to
  24.      run within a specified time limit after the occurrence of an event.
  25.  
  26.      IRIX guarantees deterministic response of one millisecond on certain
  27.      uni-processor systems.  This realtime strategy guarantees the highest
  28.      priority thread will execute within one millisecond from the time it was
  29.      made runnable.
  30.  
  31.      On certain multi-processor machines (OCTANE, Origin200, Origin2000,
  32.      Onyx2, Origin 3000 series, and Onyx3), the one millisecond bounded
  33.      response time guarantee is controlled by the systune variable _r_t_c_p_u_s.
  34.      rtcpus represents a threshold at which the scheduler functionality that
  35.      is required to meet this guarantee is enabled.  The threshold is based on
  36.      the number of physical cpus in the system.  If rtcpus is set greater than
  37.      or equal to the number of physical processors, the bounded response
  38.      guarantee is enabled.  If rtcpus is set below the number of physical
  39.      processors in the machine, the bounded response time guarantee is NOT
  40.      enabled.  The default value for rtcpus is 0, which means that by default,
  41.      the guarantee is not enabled.  In order to enable the guarantee, rtcpus
  42.      must be set equal to or greater than the number of cpus in the system.
  43.      As an example, consider a four processor system.  If rtcpus is set at a
  44.      value etween 0 and 3 (inclusive), the realtime guarantee is not enabled.
  45.      If rtcpus is set at 4 or greater, the realtime guarantee is enabled.
  46.      Note that enabling the realtime guarantee may cause overall system
  47.      performance to degrade.
  48.  
  49.      Realtime applications requiring a lower latency guarantee can use the
  50.      multi-processor realtime strategy to obtain a deterministic response of
  51.      200 microseconds.  This strategy typically consists of having one
  52.      processor service unpredictable loads, such as interrupts and system
  53.      daemons, and the other processor(s) servicing high-priority realtime
  54.      jobs.
  55.  
  56.      _CCCC_llll_oooo_cccc_kkkk_ssss
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. rrrreeeeaaaallllttttiiiimmmmeeee((((5555))))                                                        rrrreeeeaaaallllttttiiiimmmmeeee((((5555))))
  71.  
  72.  
  73.  
  74.      In order to perform event timing, IRIX provides the POSIX 1003.1b
  75.      _c_l_o_c_k__g_e_t_t_i_m_e(2) interface.  This interface can be used to access various
  76.      system clocks, including: the realtime clock, and a low overhead free
  77.      running hardware counter.
  78.  
  79.      _TTTT_iiii_mmmm_eeee_rrrr_ssss
  80.  
  81.      IRIX implements both BSD itimers and POSIX 1003.1b timers.  POSIX timers
  82.      are recommended For realtime application development, as they provide the
  83.      highest resolution and flexibility (see _t_i_m_e_r__c_r_e_a_t_e(3c)).
  84.  
  85.      Timer expiration interrupts are dispatched to IRIX interrupt threads for
  86.      handling.  The priority at which these threads are scheduled is
  87.      determined by the scheduling policy and priority of the thread which set
  88.      the timer:
  89.  
  90.           If the thread setting the timer is running with a timeshare
  91.           scheduling policy, then the associated interrupt thread will be
  92.           scheduled at realtime priority one.
  93.  
  94.           If the thread setting the timer is running with a realtime
  95.           scheduling policy, then the priority of the associated interrupt
  96.           thread will be the priority of the setting thread plus one. Priority
  97.           255, being the maximum realtime band priority, is an exception. If
  98.           the thread setting the timer is running at priority 255, then the
  99.           interrupt thread will also be scheduled at priority 255. Hence,
  100.           realtime applications depending on system services shouldn't use
  101.           priority 255 (see the _RRRR_eeee_aaaa_llll_tttt_iiii_mmmm_eeee _PPPP_rrrr_iiii_oooo_rrrr_iiii_tttt_yyyy _BBBB_aaaa_nnnn_dddd Section below).
  102.  
  103.      Once the timer expires, the interrupt thread will be scheduled ahead of
  104.      the thread which set the timer.
  105.  
  106.      _SSSS_iiii_gggg_nnnn_aaaa_llll_ssss
  107.  
  108.      IRIX supports the full semantics of both BSD and AT&T signals.  In
  109.      addition IRIX has implemented the POSIX 1003.1b queued signals which
  110.      provide signal priorities and for queuing of signals such that exactly as
  111.      many signals are received as were sent (see _s_i_g_q_u_e_u_e(3)).
  112.  
  113.      _MMMM_eeee_mmmm_oooo_rrrr_yyyy _LLLL_oooo_cccc_kkkk_iiii_nnnn_gggg
  114.  
  115.      A realtime application can avoid the overhead of page fault processing
  116.      under IRIX by locking ranges of its text and data into memory.  The POSIX
  117.      _m_l_o_c_k_a_l_l(3c) system call can be used to lock down a process's entire
  118.      virtual address space.  Since it is not always desirable to lock down the
  119.      entire virtual address space, IRIX provides the following system calls to
  120.      lock and unlock a specified range of addresses in memory:
  121.      _m_p_i_n(2)/_m_u_n_p_i_n(2) and _m_l_o_c_k(3c)/_m_u_n_l_o_c_k(3c).  The major difference
  122.      between the two sets is that mpin/munpin maintains a per page lock
  123.      counter and mlock/munlock does not.  Developers should choose the set
  124.      that best suits their application and stick with it, as mixing the
  125.      interfaces may result in unexpected behavior.
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. rrrreeeeaaaallllttttiiiimmmmeeee((((5555))))                                                        rrrreeeeaaaallllttttiiiimmmmeeee((((5555))))
  137.  
  138.  
  139.  
  140.      _AAAA_ssss_yyyy_nnnn_cccc_hhhh_rrrr_oooo_nnnn_oooo_uuuu_ssss _IIII_////_OOOO
  141.  
  142.      IRIX implements the POSIX 1003.1b interface to asynchronous I/O.  Using
  143.      this facility a programmer can queue a read or write request to a device
  144.      and optionally receive a queued signal when the request completes.  The
  145.      _r_e_a_d() or _w_r_i_t_e() call will return when the request is queued rather than
  146.      blocking the process pending completion of the I/O.  Optionally, process
  147.      priority can be used to establish the order in which queued requests are
  148.      completed.
  149.  
  150.      _PPPP_OOOO_SSSS_IIII_XXXX _TTTT_hhhh_rrrr_eeee_aaaa_dddd _SSSS_cccc_oooo_pppp_eeee
  151.  
  152.      POSIX threads (pthreads) supports both process and system scope threads.
  153.      System scope threads enable pthread applications to obtain predictable
  154.      scheduling behavior on a system level by using the kernel scheduler
  155.      directly, bypassing the user-level pthread scheduler.  For more
  156.      information about the pthread scheduling model, see _p_t_h_r_e_a_d(5).
  157.  
  158.      _TTTT_iiii_mmmm_eeee_ssss_hhhh_aaaa_rrrr_eeee _SSSS_cccc_hhhh_eeee_dddd_uuuu_llll_iiii_nnnn_gggg
  159.  
  160.      IRIX has an earnings-based scheduler for timeshare threads.  Processes
  161.      earn cpu microseconds of time base on their proportional share of the
  162.      system. Their share of the system, and thus the rate at which they
  163.      accumulate earnings, is determined by their nice value.
  164.  
  165.      While timeshare threads are not priority scheduled, they do have an
  166.      independent timeshare priority band to represent _n_i_c_e(2) values.  This
  167.      band ranges from a low priority of 1 to a high priority of 40.  A change
  168.      in either the timeshare priority or the nice value results in a
  169.      corresponding change to the nice value or timeshare priority
  170.      respectively.
  171.  
  172.      Timeshare threads which are not the beneficiaries of priority inheritance
  173.      are never scheduled ahead of realtime threads.
  174.  
  175.      _BBBB_aaaa_tttt_cccc_hhhh _SSSS_cccc_hhhh_eeee_dddd_uuuu_llll_iiii_nnnn_gggg
  176.  
  177.      Refer to _m_i_s_e_r(5).
  178.  
  179.      _RRRR_eeee_aaaa_llll_tttt_iiii_mmmm_eeee _SSSS_cccc_hhhh_eeee_dddd_uuuu_llll_iiii_nnnn_gggg
  180.  
  181.      IRIX supports the POSIX 1003.1b realtime scheduler interfaces, including:
  182.      _s_c_h_e_d__s_e_t_s_c_h_e_d_u_l_e_r(2) and _s_c_h_e_d__s_e_t_p_a_r_a_m(2).
  183.  
  184.      These interfaces provide privileged applications with the control
  185.      necessary for managing the cycles of the system processor(s).  Realtime
  186.      scheduling policies, such as round-robin and first-in-first-out, may be
  187.      selected along with a realtime priority.
  188.  
  189.      _RRRR_eeee_aaaa_llll_tttt_iiii_mmmm_eeee _PPPP_rrrr_iiii_oooo_rrrr_iiii_tttt_yyyy _BBBB_aaaa_nnnn_dddd
  190.  
  191.  
  192.  
  193.  
  194.  
  195.                                                                         PPPPaaaaggggeeee 3333
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202. rrrreeeeaaaallllttttiiiimmmmeeee((((5555))))                                                        rrrreeeeaaaallllttttiiiimmmmeeee((((5555))))
  203.  
  204.  
  205.  
  206.      A realtime thread may select one of a range of 256 priorities (0-255) in
  207.      the realtime priority band, using POSIX interfaces _s_c_h_e_d__s_e_t_p_a_r_a_m() or
  208.      _s_c_h_e_d__s_e_t_s_c_h_e_d_u_l_e_r().
  209.  
  210.      The higher the numeric value of the priority the more important the
  211.      thread.
  212.  
  213.      Developers must consider the needs of the application and how it should
  214.      interact with the rest of the system, before selecting a realtime
  215.      priority.  To aid in this decision, the priorities of the system threads
  216.      should be considered.
  217.  
  218.      IRIX manages system threads to handle kernel tasks, such as paging and
  219.      interrupts. System daemon threads execute between priority range _9_0 _a_n_d
  220.      _1_0_9 inclusive, and system device driver interrupt threads execute between
  221.      priority range _2_0_0 _a_n_d _2_3_9 inclusive (see the following section for more
  222.      information about interrupt threads).
  223.  
  224.      An application may set the priorities of its threads above that of the
  225.      system threads, but this may effect the behavior of the system. For
  226.      example, if the disk interrupt thread is blocked by higher priority user
  227.      thread, disk data access will be delayed, pending completion of the user
  228.      thread.
  229.  
  230.      Setting the priorities of application threads within or above the system
  231.      thread ranges requires an advanced understanding of IRIX system threads
  232.      and their priorities.  The priorities of the IRIX system threads may be
  233.      found in /_v_a_r/_s_y_s_g_e_n/_m_t_u_n_e/_k_e_r_n_e_l.  If necessary, these defaults may be
  234.      changed using _s_y_s_t_u_n_e(1M), although this is not recommended for most
  235.      users.
  236.  
  237.      Many soft realtime applications simply need to execute ahead of timeshare
  238.      applications, in which case priority range 0 through and including 89 is
  239.      best suited.  Since timeshare applications are not priority scheduled, a
  240.      thread running at the lowest realtime priority (0) will still execute
  241.      ahead of all timeshare applications.  Note, however, that at times the
  242.      operating system briefly promotes timeshare threads into the realtime
  243.      band to handle timeouts, and avoid priority inversion.  In these special
  244.      cases, the promoted thread's realtime priority is never boosted higher
  245.      than 1.
  246.  
  247.      Applications cannot depend on system services if they are running ahead
  248.      of the system, without observing the system responsiveness timing
  249.      guidelines below.
  250.  
  251.      Interactive realtime applications (such as digital media) need low
  252.      latency response times from the operating system, but changing interrupt
  253.      thread behavior is undesirable. In this case, priority range 110 through
  254.      and including 199 is best suited, allowing execution ahead of system
  255.      daemons but behind interrupt threads.  Applications in this range are
  256.      typically cooperating with a device driver, in which case, the correct
  257.      priority for the application is the priority of the device driver
  258.  
  259.  
  260.  
  261.                                                                         PPPPaaaaggggeeee 4444
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268. rrrreeeeaaaallllttttiiiimmmmeeee((((5555))))                                                        rrrreeeeaaaallllttttiiiimmmmeeee((((5555))))
  269.  
  270.  
  271.  
  272.      interrupt thread minus 50 (see the following section). If the application
  273.      is multi-threaded, and multiple priorities are warranted, then the
  274.      priorities of the threads should be no greater than the priority of the
  275.      device driver interrupt thread minus 50. Note that threads running at a
  276.      higher priority than system daemon threads should never run for more than
  277.      a few milliseconds at a time, in order to preserve system responsiveness.
  278.  
  279.      Hard realtime applications may use priorities 240 through and including
  280.      254 for the most deterministic behavior and the lowest latencies.
  281.      However, if a thread running at this priority ever gets into a state
  282.      where it is using 100% of the processor, the system may become completely
  283.      unresponsive.  Threads running at a higher priority than the interrupt
  284.      threads should never run for more that a few hundred microseconds at a
  285.      time, in order to preserve system responsiveness.
  286.  
  287.      Priority 255, the highest realtime priority, should not be used by
  288.      applications.  This priority is reserved for system use in order to
  289.      handle timers for urgent realtime applications, and kernel debugger
  290.      interrupts.  Applications executing at this priority run the risk of
  291.      hanging the system.
  292.  
  293.      The proprietary IRIX interface for selecting a realtime priority,
  294.      _s_c_h_e_d_c_t_l(), is still supported for binary compatibility, but it is no
  295.      longer the interface of choice.  The non-degrading realtime priority
  296.      range of schedctl() is re-mapped onto the POSIX realtime priority band as
  297.      priorities 90 through 118 as follows: 39=90, 38=110, 37=111, 36=112,
  298.      35=113, 34=114, etc..  Note that the large gap between the first two
  299.      priorities preserves the scheduling semantics of schedctl() threads and
  300.      system daemons.
  301.  
  302.      Realtime users are encouraged to use tools such as par(1) and irixview(1)
  303.      to observe the actual priorities and dynamic behaviors of all threads on
  304.      a running system.
  305.  
  306.      _DDDD_eeee_vvvv_iiii_cccc_eeee _DDDD_rrrr_iiii_vvvv_eeee_rrrr _IIII_nnnn_tttt_eeee_rrrr_rrrr_uuuu_pppp_tttt _TTTT_hhhh_rrrr_eeee_aaaa_dddd _PPPP_rrrr_iiii_oooo_rrrr_iiii_tttt_iiii_eeee_ssss
  307.  
  308.      As of IRIX 6.4, device drivers employ interrupt threads to handle device
  309.      interrupts. Interrupt threads have default priorities in the range 200
  310.      through and including 239.
  311.  
  312.      To make selecting an appropriate priority for an interrupt thread easier,
  313.      IRIX defines device classes including: audio, video, network, disk,
  314.      serial, parallel, tape, external.  Each device class has a priority
  315.      assigned to it.  A complete listing of device classes, and their default
  316.      priorities, can be found in /_v_a_r/_s_y_s_g_e_n/_m_t_u_n_e/_k_e_r_n_e_l.
  317.  
  318.      For example, the value of _n_e_t_w_o_r_k__i_n_t_r__p_r_i defines the interrupt thread
  319.      priority of all network class devices.
  320.  
  321.      A device driver may set the priority of its interrupt thread to one of
  322.      the defined classes, by using the class directive in its driver
  323.      configuration file (located in the /var/sysgen/master.d directory).
  324.  
  325.  
  326.  
  327.                                                                         PPPPaaaaggggeeee 5555
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334. rrrreeeeaaaallllttttiiiimmmmeeee((((5555))))                                                        rrrreeeeaaaallllttttiiiimmmmeeee((((5555))))
  335.  
  336.  
  337.  
  338.      For example, /var/sysgen/master.d/if_ef includes the directive
  339.  
  340.           +thread_class  network
  341.  
  342.      which means that the value of the systune(1M) variable _n_e_t_w_o_r_k__i_n_t_r__p_r_i
  343.      will be used for the interrupt thread priority of this device.
  344.  
  345.      Devices whose class cannot be determined use the value of the variable
  346.      _d_e_f_a_u_l_t__i_n_t_r__p_r_i:
  347.  
  348.           +thread_class  default
  349.  
  350.      The default priority of each device class may be changed using the
  351.      appropriate systune(1M) variable in /_v_a_r/_s_y_s_g_e_n/_m_t_u_n_e/_k_e_r_n_e_l.
  352.  
  353.      The thread_class value may be overridden for a particular driver by
  354.      adding the _t_h_r_e_a_d__p_r_i_o_r_i_t_y directive to the driver description file.  For
  355.      example:
  356.  
  357.           +thread_priority    205
  358.  
  359.      On systems supporting the hardware graph, both of these values may be
  360.      overridden for a particular device by using the DEVICE_ADMIN directive
  361.      with the INTR_SWLEVEL attribute in the /var/sysgen/system/irix.sm file
  362.      (q.v. for an example of this usage).
  363.  
  364.      _PPPP_rrrr_oooo_cccc_eeee_ssss_ssss_oooo_rrrr _CCCC_oooo_nnnn_tttt_rrrr_oooo_llll
  365.  
  366.      Using the _s_y_s_m_p() call or the _m_p_a_d_m_i_n and _r_u_n_o_n commands a programmer may
  367.      control the distribution of processes among the processors in a realtime
  368.      system.  For instance, it is possible to bind a particular process onto a
  369.      processor and conversely, it is possible to restrict a processor to only
  370.      run those processes that are explicitly bound to it.  This makes it
  371.      possible to dedicate one or more processors to particular processes.
  372.  
  373.      Nominally, when IRIX is running in a multiprocessor certain system
  374.      services require synchronization of all processors in the complex.  This
  375.      is mainly done to synchronize the instruction caches and to synchronize
  376.      the virtual to physical translation caches or tlbs.  In order to reduce
  377.      the worst case dispatch latency a processor can be _i_s_o_l_a_t_e_d using the
  378.      _s_y_s_m_p() call.  This allows a process some control over when these
  379.      synchronizing events take place.  If the process never requests system
  380.      services then there is no need to synchronize.  If the process is sharing
  381.      address space with other processes through use of either _s_p_r_o_c() or
  382.      _s_p_r_o_c_s_p() then members of the share group should also avoid operations
  383.      that would require IRIX to synchronize with the isolated processor.
  384.      These include operations that explicitly flush caches, expand address
  385.      space across 4 megabyte boundaries, release address space or change
  386.      address space protections.  Creation of new share group members through
  387.      the use of _s_p_r_o_c() requires the creation of a stack area which may result
  388.      in a synchronization event.  Use of the _s_p_r_o_c_s_p() interface specifying a
  389.      stack in section of locked memory is recommended.
  390.  
  391.  
  392.  
  393.                                                                         PPPPaaaaggggeeee 6666
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400. rrrreeeeaaaallllttttiiiimmmmeeee((((5555))))                                                        rrrreeeeaaaallllttttiiiimmmmeeee((((5555))))
  401.  
  402.  
  403.  
  404.      _s_y_s_m_p() can also be used to turn off normal IRIX clock processing on a
  405.      particular processor and thus normal IRIX time slicing will not preempt
  406.      the running process.  Thus, if a processor is isolated, no devices are
  407.      configured onto that processor, the clock service is disabled, the
  408.      application process is restricted to the isolated processor and its
  409.      virtual space is locked in memory then a user can achieve a fast bounded
  410.      response time to an external event.
  411.  
  412.      _IIII_nnnn_tttt_eeee_rrrr_rrrr_uuuu_pppp_tttt _RRRR_eeee_dddd_iiii_rrrr_eeee_cccc_tttt_iiii_oooo_nnnn
  413.  
  414.      When the multi-processor realtime strategy is being used, it is often
  415.      necessary to redirect unwanted PCI and VME interrupts away from the
  416.      realtime processors.
  417.  
  418.      Control over which device interrupts are sent to which processor can be
  419.      achieved by adding DEVICE_ADMIN directives to the /_u_s_r/_s_y_s_g_e_n/_s_y_s_t_e_m
  420.      file.
  421.  
  422.      The NOINTR directive may also be used to guarantee that no interrupts are
  423.      randomly assigned for handling by the realtime processor.  After the
  424.      system file is modified _l_b_o_o_t should be run to reconfigure the system.
  425.  
  426. SSSSEEEEEEEE AAAALLLLSSSSOOOO
  427.      lboot(1), mpadmin(1), runon(1), systune(1M), mlockall(3c), mpin(2),
  428.      munpin(2), plock(2), sched_setparam(2), sched_setscheduler(2), sproc(2),
  429.      sysmp(2), syssgi(2), aio_error(3), aio_read(3), aio_return(3),
  430.      aio_write(3), lio_listio(3), system(4), signal(5), sigqueue(3)
  431.      timer_create(3c), pthread(3p) nice(1), renice(1m)
  432.  
  433.  
  434.  
  435.  
  436.  
  437.  
  438.  
  439.  
  440.  
  441.  
  442.  
  443.  
  444.  
  445.  
  446.  
  447.  
  448.  
  449.  
  450.  
  451.  
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459.                                                                         PPPPaaaaggggeeee 7777
  460.  
  461.  
  462.  
  463.